/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game;

import framework.GForm;
import framework.GMouseManager;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

/**
 *
 * @author bryan
 */
public class MainGame extends Frame implements Runnable{
   
   Background background;
   GMouseManager mousemanager;
   Mallet mallet;
   Hole hole1;
   Hole hole2;
   Hole hole3;
   Hole hole4;
   Hole hole5;
   MoleRat molerat;
   
   public static void main(String args[]) {
      (new Thread(new MainGame(""))).start();
   }
   private Graphics2D Graphics2D;
   
   public MainGame(String title) {
      super(title);
      setSize(450, 338);
      mousemanager = new GMouseManager();
      addMouseListener(mousemanager);
      addMouseMotionListener(mousemanager);
      background = new Background();
      mallet = new Mallet();
      
      hole1 = new Hole(50, 300);
      hole2 = new Hole(200, 300);
      hole3 = new Hole(90,200);
      hole4 = new Hole(300,200);
      hole5 = new Hole(230,200);
      molerat = new MoleRat(45,300);
      
      GForm.attachClose(this);
      GForm.centralize(this);
   }

   @Override
   public void run() {
      while(true) {
         mallet.animate();
         molerat.animate();
         repaint();
      }
   }
   
   public void update(Graphics g) {
      paint(g);
   }
   
   public void paint(Graphics g) {
      Image canvas = createImage(450, 338);
      Graphics2D g2 = (Graphics2D) canvas.getGraphics();
      background.render(g2);
      hole5.renderT(g2);
      hole5.renderB(g2);
      hole4.renderTop(g2);
      hole4.renderBottom(g2);
      hole3.renderTop(g2);
      hole3.renderBottom(g2);
      hole1.renderTop(g2);
      molerat.render(g2);
      hole1.renderBottom(g2);
      hole2.renderTop(g2);
      hole2.renderBottom(g2);
      mallet.render(g2);
      
      g.drawImage(canvas, 0, 0, 450, 338, this);
   }
   
}
